package com.fdd.furns.web;

import com.fdd.furns.pojo.Member;
import com.fdd.furns.service.AdminService;
import com.fdd.furns.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/manage/adminServlet")
public class AdminServlet extends BasicServlet {

    private AdminService adminService = new AdminServiceImpl();

    protected void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        if (adminService.login(username, password)) {
            //登录成功
            Member admin = new Member(0, username, password, null);
            req.getSession().setAttribute("member", admin);
            req.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(req, resp);
        }else{
            //登录失败
            System.out.println("用户名或密码错误");
            req.setAttribute("errorMes02", "用户名或密码错误");
            req.getRequestDispatcher("/views/manage/manage_login.jsp").forward(req, resp);
        }
    }
}
